var GroupLoader = [];
var prefixGroupCate = "group_categories_";
var prefixGroupChecktion= "group_checktion_";

function expandGroup(groupId,objMe){
    var categories = document.getElementById(prefixGroupCate+groupId);
    
    if(GroupLoader[groupId] === undefined  
            || GroupLoader[groupId] === null){
        var url = "/product-group/getCategories";
        var params = new Array();
        params["group_id"] = groupId;
        var result = Ajax.callFunction(url, params);
        for(var i=0;i<result.length;i++){
            var item = document.createElement("li");
            item.innerHTML = result[i].CATEGORY_NAME + " ("+result[i].TOTAL_PRODUCT+")";
            categories.appendChild(item);
        }
        GroupLoader[groupId] = result.length;
        categories.style.display = "none";
    }
    
    if(GroupLoader[groupId] > 0){
        if(categories.style.display !== ''){
            objMe.className = "group_expand";
            categories.style.display = '';
        }else{
            objMe.className = "group_inpand";
            categories.style.display = 'none';
        }
    }
    
}

//Override
Page.load = function(){
    Navigation.show();
    Panel.show();
    
    //FPopup
    FPopup.loading = function(){
        LoadingIcon.show();
    };

    FPopup.stopLoading = function(){
        LoadingIcon.hide();
    };

    FPopup.callAsyncFunction= function(url,params,callBack){
        Ajax.callAsyncFunction(url,params,callBack);
    };

    FPopup.closeIconClassName = "close_icon_fpopup";
    
    //Loading icon
    LoadingIcon.popupClassName = "loading";
};

function showCategoryPopup(groupId,url){
    hideAllCategoryPopup();
    var params = new Array();
    params["group_id"] = groupId;
    FPopup.showDialogIFrame(url,params);
}

function hideAllCategoryPopup(){
    var className = "group_inpand";
    var categoryPopups = document.getElementsByClassName(className);
    var i;
    for(i=0;i<categoryPopups.length;i++){
        categoryPopups[i].className = "group_expand";
    }
    for (var key in GroupLoader) {
        document.getElementById(prefixGroupCate+key).style.display="none";
    }
    
}